#!/bin/bash

# initial value
opt_testall=0
opt_gran=256
opt_thread=1


# read from formatted parameters
while getopts ":ai:g:t:" opt; do 
  case $opt in
    a)
        opt_testall=1 ;;
    g)
        opt_gran=$OPTARG ;;
    t)
        opt_thread=$OPTARG ;;
    i) 
        id=$OPTARG ;;
    :)
        echo "Option -$OPTARG requires an argument!" 
        exit 1 ;;
    ?)
        echo "Invalid option: -$OPTARG!" ;;
  esac
done

# test start
if [[ $opt_testall -eq 1 ]]; then
    grans="64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072"
    threads="1 2 4 8 12 16 20 24 28"
    # test under different threads and granularity
    for t in $threads; do
        for g in $grans; do
            echo -n "$t $g "
            taskset -c 0-17,36-53 ./bandwidth -i $id -t $t -g $g -p 0
            #taskset -c 18-35,54-71 ./bandwidth -i $id -t $t -g $g -p 0
            #./bandwidth -i $id -t $t -g $g -p 0
        done
    done
else
    echo -n "$opt_thread $opt_gran "
    taskset -c 0-17,36-53 ./bandwidth -i $id -t $opt_thread -g $opt_gran -p 0
    #taskset -c 18-35,54-71 ./bandwidth -i $id -t $opt_thread -g $opt_gran -p 0
    #./bandwidth -i $id -t $opt_thread -g $opt_gran -p 0
fi
